##########################################################
# MASTER                                                ##
#                                                       ##
# "Empty Promises and Non-Incorporation in Mercosur"    ##
# International Interactions                            ##
# Chris Arnold                                          ##
# May 2016                                              ##
# Implemented on Zelig 5 and R 3.2.3                    ##
##########################################################





# ============
# = Packages =
# ============

library(survival)
library(Zelig)
library(lattice)
library(dummies)
library(MASS)
library(stargazer)

# ========
# = Data =
# ========

# master data
load("data/master.Rdata")

## Event History Format
# without imputation
load(file = "data/eha_data.Rdata")

# with imputation
load("data/eha_data1.Rdata")
load("data/eha_data2.Rdata")
load("data/eha_data3.Rdata")
load("data/eha_data4.Rdata")
load("data/eha_data5.Rdata")


# =============
# = Functions =
# =============

# Functions for quantiles
low <- function(x){
	quantile(x, .025, na.rm = TRUE)
}
high <- function(x){
	quantile(x, .975, na.rm = TRUE)
}




# ================
# = Descriptives =
# ================

source("figures/figure1.r", chdir = TRUE)
source("figures/figure2.r", chdir = TRUE)
source("figures/table1.r", chdir = TRUE)
source("figures/table2.r", chdir = TRUE)




# ============================
# = Stage 1: Decision making =
# ============================

# Analyse data and make postpreds for the Observable Implication 
# Figure and Table from the appendix
source("stage1/s1_analysis.r", chdir = TRUE)


# ==========================
# = Stage 2: Incorporation =
# ==========================

# This does the analysis 
# Also charts results and creates figures 3a) and 3b)
source("stage2/s2_analysis.r", chdir = TRUE)
